package com.macro.mall.common.exception;

import com.macro.mall.common.api.IErrorCode;
import org.springframework.http.HttpStatus;

public class ApiException extends RuntimeException {
    private IErrorCode errorCode;

    public ApiException(IErrorCode errorCode) {
        super(errorCode.getMessage());
        this.errorCode = errorCode;
    }

    public ApiException(String message) {
        super(message);
    }

    public ApiException(Throwable cause) {
        super(cause);
    }

    public ApiException(String message, Throwable cause) {
        super(message, cause);
    }

    public ApiException(String message, HttpStatus httpStatus) {
        super(message);
        this.errorCode = new IErrorCode() {
            @Override
            public int getCode() {
                return httpStatus.value();
            }

            @Override
            public String getMessage() {
                return message;
            }
        };
    }

    public IErrorCode getErrorCode() {
        return errorCode;
    }
}
